package com.example.springbootpay.service.impl;

import com.example.springbootpay.service.AbstractPaymentTemplate;
import com.example.springbootpay.service.PaymentService;
import com.example.springbootpay.service.PaymentStrategyFactory;
import org.springframework.stereotype.Service;

@Service
public class PaymentServiceImpl implements PaymentService {
    
    private final PaymentStrategyFactory paymentFactory;

    public PaymentServiceImpl(PaymentStrategyFactory paymentFactory) {
        this.paymentFactory = paymentFactory;
    }

    @Override
    public String unifiedOrder(Integer amount) {
        AbstractPaymentTemplate strategy = paymentFactory.getStrategy("alipay");
        return strategy.processPayment(amount);
    }

    @Override
    public String orderQuery(String orderId) {
        AbstractPaymentTemplate strategy = paymentFactory.getStrategy("alipay");
        return strategy.doOrderQuery(orderId);
    }

    @Override
    public String refund(String orderId, Integer amount) {
        AbstractPaymentTemplate strategy = paymentFactory.getStrategy("alipay");
        return strategy.doRefund(orderId, amount);
    }
}